<template>
  <div class="projectlist-container">
    <el-row class="projectlist-top dm-form">
      <el-col :xs="{ span: 24 }"
              :sm="{ span: 6 }"
              :lg="{ span: 6 }"
              :md="{ span: 6 }">
        <el-input v-model="filterParams.project_name"
                  placeholder="项目名称"></el-input>
      </el-col>

      <el-col :xs="{ span: 24 }"
              :sm="{ span: 12 }"
              :lg="{ span: 12 }"
              :md="{ span: 12 }"
              class="location">
        <LocationSelect :locaData.sync="requestParam"></LocationSelect>
      </el-col>
      <el-col class="date-range"
              :xs="{ span: 24 }"
              :sm="{ span: 6 }"
              :lg="{ span: 6 }"
              :md="{ span: 6 }">
        <el-date-picker v-model="dateRange"
                        type="daterange"
                        range-separator="-"
                        start-placeholder="开始日期"
                        end-placeholder="结束日期"
                        :default-time="['00:00:00', '23:59:59']"
                        value-format="yyyy-MM-dd HH:mm:ss"></el-date-picker>
      </el-col>
      <el-col :xs="{ span: 24 }"
              :sm="{ span: 6 }"
              :lg="{ span: 6 }"
              :md="{ span: 6 }">
        <el-select v-model="filterParams.is_bind_jt_project"
                   placeholder="项目绑定">
          <el-option v-for="item in bindingList"
                     :key="item.value"
                     :label="item.label"
                     :value="item.value"></el-option>
        </el-select>
      </el-col>
      <!-- <el-col class="status-select"
              :xs="{ span: 12 }"
              :sm="{ span: 6 }"
              :lg="{ span: 6 }"
              :md="{ span: 6 }">
        <el-select v-model="requestParam.major_type"
                   placeholder="专业类型">
          <el-option label="全部"
                     value=""> </el-option>
          <el-option v-for="item in majorTypeList"
                     :key="item.value"
                     :label="item.name"
                     :value="item.value">
          </el-option>
        </el-select>
      </el-col>-->
      <!-- <el-col :span="6">
        <el-select v-model="requestParam.is_indust_project"
                   placeholder="是否工业化项目">
          <el-option label="是"
                     value="1"></el-option>
          <el-option label="否"
                     value="0"></el-option>
        </el-select>
      </el-col>-->
      <el-col v-if="isHTM"
              :lg="{span:6}"
              :xs="{span:12}"
              :sm="{span:12}"
              :md="{span:12}">
        <el-button @click="downloadBIM"
                   type="primary">下载内装插件</el-button>
      </el-col>
      <el-col :lg="{ span: 6, offset: isHTM?6:12}"
              :xs="{ span: 24 }"
              :sm="{ span: 12, offset: isHTM?0:6 }"
              :md="{ span: 12, offset: isHTM?0:6 }"
              class="header-right-button">
        <!-- <el-button type="primary"
        @click="onMainContractInitPro()">根据主合同立项</el-button>-->
        <el-button v-auth="'create-industry-btn'"
                   icon="el-icon-plus"
                   type="primary"
                   @click="createIndustyProject">新增工业化项目</el-button>
        <el-button icon="el-icon-search"
                   class="search-btn"
                   @click="search"
                   type="primary">查询</el-button>
        <!-- :type="isLookDataAuth==true?'primary':'info'"
        :disabled="isLookDataAuth==true?false:true"-->
        <!-- v-auth="'create-project-btn'" -->
        <el-button v-show="isShowAddProBtn"
                   icon="el-icon-plus"
                   type="primary"
                   @click="createProject">新增项目</el-button>
        <el-button type="primary"
                   @click="printButton('create-project-btn',requestParam)">打印</el-button>
        <el-button @click="reset">重置</el-button>
      </el-col>
    </el-row>
    <el-row class="projectlist-top dm-form">
      <!-- <el-col class="status-select"
              :span="4">
        <el-select v-model="requestParam.status"
                   placeholder="项目状态">
          <el-option v-for="(item, index) in projectStatusList"
                     :key="index"
                     :label="item.name"
                     :value="item.value">
          </el-option>
        </el-select>
      </el-col>-->
      <!-- <el-col :span="4">
        <el-select v-model="requestParam.business_type_list"
                   multiple
                   placeholder="选择业务类型"
                   @change="chooseBusinessType">
          <el-option v-for="item in businessTypeList"
                     :key="item.value"
                     :label="item.name"
                     :value="item.value"
                     :disabled="item.content1 === ''">
          </el-option>
        </el-select>
      </el-col>-->
    </el-row>
    <el-row class="projectlist-mid">
      <!-- <el-col :span="24"
              class="checkbox-col">
        <span class="checkbox-span">选择显示：</span>
        <el-checkbox :indeterminate="isIndeterminate"
                     class="checkbox-all"
                     v-model="checkAll"
                     @change="handleCheckAllChange">全选</el-checkbox>
        <el-checkbox-group v-model="checkedCities"
                           class="checkbox-item"
                           @change="handleCheckedCitiesChange">
          <el-checkbox v-for="city in cities"
                       :label="city"
                       :key="city">{{city}}</el-checkbox>
        </el-checkbox-group>
      </el-col>-->
      <el-col :span="24"
              class="table-col">
        <el-table :highlight-current-row="true"
                  border
                  :header-cell-style="{ background: '#f5f5f5' }"
                  :data="projectList.list">
          <el-table-column type="index"
                           label="序号"
                           sortable
                           align="center"
                           :sort-method="sortNo"
                           width="100"
                           show-overflow-tooltip></el-table-column>
          <el-table-column prop="project_no"
                           label="项目编号"
                           sortable
                           align="center"
                           show-overflow-tooltip>
            <template slot-scope="scope">
              <p>{{ ("0000" + scope.row.project_id).substr(-5, 5) }}</p>
            </template>
          </el-table-column>
          <el-table-column label="项目简称"
                           prop="nick_name"
                           align="center"></el-table-column>
          <el-table-column label="项目名称"
                           show-overflow-tooltip
                           prop="project_name"
                           align="center"></el-table-column>
          <!-- <el-table-column prop="majorTypeName"
                           label="专业类型"
                           sortable
                           align="center"
                           show-overflow-tooltip>
          </el-table-column>-->
          <el-table-column prop="address"
                           label="项目地址"
                           align="center"
                           show-overflow-tooltip></el-table-column>
          <!-- <el-table-column prop="statusName"
                           label="项目状态"
                           align="center"
                           show-overflow-tooltip>
          </el-table-column>-->
          <el-table-column label="项目绑定"
                           prop="is_bind_jt_project"
                           align="center"></el-table-column>
          <el-table-column prop="project_leader_name"
                           label="项目经理"
                           sortable
                           align="center"
                           show-overflow-tooltip>
            <template slot-scope="scope">
              <p>{{ scope.row.leader_name }}</p>
              <!-- <p>{{ scope.row.leader_phone }}</p> -->
            </template>
          </el-table-column>
          <el-table-column prop="process_status"
                           label="进度"
                           align="center"
                           v-if="checkedCities.indexOf('进度') != -1 ? true : false"
                           show-overflow-tooltip></el-table-column>
          <el-table-column prop="make_embed"
                           label="制作预埋"
                           align="center"
                           v-if="checkedCities.indexOf('加工制作') != -1 ? true : false"
                           show-overflow-tooltip></el-table-column>
          <el-table-column prop="fac_stack"
                           label="工厂堆放"
                           align="center"
                           v-if="checkedCities.indexOf('工厂堆放') != -1 ? true : false"
                           show-overflow-tooltip></el-table-column>
          <el-table-column prop="member_ship"
                           label="构件运输"
                           align="center"
                           v-if="checkedCities.indexOf('构件运输') != -1 ? true : false"
                           show-overflow-tooltip></el-table-column>
          <el-table-column prop="spot_stack"
                           label="现场堆放"
                           align="center"
                           v-if="checkedCities.indexOf('现场堆放') != -1 ? true : false"
                           show-overflow-tooltip></el-table-column>
          <el-table-column prop="spot_install"
                           label="现场安装"
                           align="center"
                           v-if="checkedCities.indexOf('现场安装') != -1 ? true : false"
                           show-overflow-tooltip></el-table-column>
          <el-table-column prop="install_complete"
                           label="安装完成"
                           align="center"
                           v-if="checkedCities.indexOf('安装完成') != -1 ? true : false"
                           show-overflow-tooltip></el-table-column>
          <el-table-column label="所属公司"
                           prop="own_company"
                           align="center"
                           v-if="checkedCities.indexOf('所属公司') != -1 ? true : false"
                           show-overflow-tooltip></el-table-column>
          <!-- <el-table-column prop="is_indust_project"
                           label="是否工业化项目"
                           align="center"
                           sortable
                           width="210px"
                           show-overflow-tooltip>
            <template slot-scope="scope">
              {{scope.row.is_indust_project==='1'?'是':'否'}}
            </template>
          </el-table-column>-->
          <!-- <el-table-column prop=""
                           label="关联项目"
                           align="center"
                           show-overflow-tooltip>
            <template slot-scope="scope">
              {{scope.row.custom_project_type =='2'?'已关联':'未关联'}}
            </template>
          </el-table-column>-->
          <el-table-column prop="created_at"
                           label="创建时间"
                           sortable
                           align="center"
                           show-overflow-tooltip></el-table-column>
          <!-- <el-table-column prop="component_sync"
                           label="构件同步"
                           align="center"
                           show-overflow-tooltip>
            <el-button type="text"
                       @click="goToDetail()">详情</el-button>
          </el-table-column>
          <el-table-column label="启动revit"
                           @click="startRevit"
                           align="center">fsfsfdsfsdf
            <el-button type="text">启动revit</el-button>
          </el-table-column>-->
          <el-table-column label="操作"
                           width="200px"
                           align="center">
            <template slot-scope="scope">
              <el-button type="text"
                         @click="publish(scope.row)"
                         v-if="isHTM">管理</el-button>
              <el-button type="text"
                         @click="uploadGantt(scope.row)"
                         v-if="isGantt">上传进度计划</el-button>
              <el-button v-if="!isHTM && !isGantt"
                         @click="onOpera(scope.row,'detail')"
                         type="text">详情</el-button>
              <el-button type="text"
                         v-if="!isHTM && !isGantt"
                         @click="onOpera(scope.row,'update')">编辑</el-button>
              <el-button v-show="isShowDelProBtn"
                         @click="deleteProject(scope.row)"
                         type="text">删除</el-button>
              <el-button type="text"
                         @click="printButton('create-project-btn', scope.row, 'table')">打印</el-button>
              <el-button type="text"
                         @click="startRevit"
                         v-if="isHTM">设计</el-button>
              <el-button type="text"
                         v-auth="'rel-pro-btn'"
                         @click="onRelProject(scope.row)">关联项目</el-button>
              <el-button type="text"
                         v-auth="'look-rel-pro-btn'"
                         @click="onRelProDetail(scope.row)">查看关联项目</el-button>
              <el-button type="text"
                         @click="onRemoveProject(scope.row)">解绑</el-button>
            </template>
          </el-table-column>
        </el-table>
        <el-col :span="24"
                style="margin-top:20px!important;">
          <el-pagination @current-change="handlePageChange"
                         :current-page="requestParam.page"
                         :page-size="requestParam.page_size"
                         layout="total,sizes,prev, pager, next, jumper"
                         background
                         :total="projectList.total_count"
                         align="center"></el-pagination>
        </el-col>
      </el-col>
    </el-row>
    <editProjectDialog :dialogVisible.sync="editProjectDialogVisible"
                       :dialogForm="editProjectDialogForm"></editProjectDialog>

    <el-dialog title="选择打印模板"
               :visible.sync="dialogVisiblePrintFlag">
      <el-table ref="singleTable"
                :data="printTemplateList"
                highlight-current-row
                @current-change="handleCurrentChange"
                style="width: 100%">
        <el-table-column property="templete_name"
                         label="模板名称"></el-table-column>
      </el-table>
      <div slot="footer"
           class="dialog-footer">
        <el-button @click="dialogVisiblePrintFlag = false">取 消</el-button>
        <el-button type="primary"
                   @click="toPrintPage">确 定</el-button>
      </div>
    </el-dialog>
    <input style="display:none;"
           accept=".mpp, .xml, text/xml, application/xml, application/vnd.ms-project, application/msproj, application/msproject, application/x-msproject, application/x-ms-project, application/x-dos_ms_project, application/mpp, zz-application/zz-winassoc-mpp"
           type="file"
           @change="fileChange"
           id="ganttFile" />
    <!-- 查看关联项目 -->
    <RelProjectLookDialog v-if="relProLookVisible==true"
                          :objRow.sync="objRow"
                          :relProLookVisible.sync="relProLookVisible"></RelProjectLookDialog>
    <GeneralAuthItemPopUpDialog v-if="geneAuthItemPopUpDialog==true"
                                :objRowGeneral.sync="objRowGeneral"
                                :currentPageName.sync="currentPageName"
                                :geneAuthItemPopUpDialog.sync="geneAuthItemPopUpDialog"></GeneralAuthItemPopUpDialog>
    <MainContractInitProDialog v-if="mainConInitProDialog"
                               :mainConInitProDialog.sync="mainConInitProDialog"></MainContractInitProDialog>
  </div>
</template>
<script>
import GeneralAuthItemPopUpDialog from "@/components/GeneralAuthItemPopUpDialog/GeneralAuthItemPopUpDialog";
import RelProjectLookDialog from "./components/RelProjectLookDialog";
import { ProjectListApi } from "@/services/ProjectCenter";
import { userPermissionApi } from "@/services/UserPermission";
import editProjectDialog from "./components/editProjectDialog";
import { standardCodeApi } from "@/services/StandardCode";
import LocationSelect from "@/components/LocationSelect/LocationSelect";
import MainContractInitProDialog from "./components/MainContractInitProDialog"; //主合同立项
const cityOptions = [
  "进度",
  "加工制作",
  "工厂堆放",
  "构件运输",
  "现场堆放",
  "现场安装",
  "安装完成",
  "所属公司"
];
export default {
  name: "platFormProjectList",
  data () {
    return {
      isShowAddProBtn: false,
      isShowDelProBtn: false,
      mainConInitProDialog: false, //主合同立项
      isLookDataAuth: false, //是否有权限，true：是，false：否
      currentPageName: "项目列表", //当前页面的名称
      objRowGeneral: {},
      geneAuthItemPopUpDialog: false,
      objRow: {}, //当前项目的对象
      relProLookVisible: false, //查看关联项目
      dialogVisiblePrintFlag: false,
      dialogTableRow: {}, // 打印选择的哪一行
      queryForm: {}, // 上面form表单，或者下面table的row
      printTemplateList: [], // 打印弹窗的模版列表
      deleteDialogVisible: false, // 删除构件弹窗
      dateRange: [], //日期
      filterParams: {
        start_time: "",
        end_time: "",
        project_name: "",
        is_bind_jt_project: ""
      },

      requestParam: {
        company_id: "",
        module_id: "3", //项目列表为3
        province_no: "",
        city_no: "",
        area_no: "",
        major_type: "",
        status: "",
        is_page: 1,
        page: 1,
        page_size: 10,
        is_indust_project: ""
      },
      resetParam: {
        province_no: "",
        city_no: "",
        area_no: "",
        module_id: "3",
        major_type: "",
        status: "",
        is_page: 1,
        page: 1,
        page_size: 10,
        is_indust_project: ""
      },
      projectList: {
        list: [],
        total: 0,
        total_count: 0
      },
      profes_type: "",
      options: [
        {
          value: "1",
          label: "测试类型"
        }
      ],
      bindingList: [
        {
          value: "1",
          label: "是"
        },
        {
          value: "0",
          label: "否"
        }
      ],
      checkAll: false,
      checkedCities: [],
      cities: cityOptions,
      isIndeterminate: true,
      // 编辑项目弹框是否可见
      editProjectDialogVisible: false,
      // 编辑项目弹框数据对象
      editProjectDialogForm: {},
      // 新增或修改项目弹框状态
      editProjectDialogStatus: "create",
      userInfo: {},
      // 专业类型列表
      majorTypeList: [],
      // 专业类型map
      majorTypeMap: new Map(),
      // 项目状态标准码列表
      projectStatusList: [
        { name: "全部状态", value: "" },
        { name: "未完成", value: "1" },
        { name: "已完成", value: "2" }
      ],
      // 业务类型标准码列表
      businessTypeList: [],
      projectId: ""
    };
  },
  components: {
    editProjectDialog,
    LocationSelect,
    RelProjectLookDialog, //查看关联项目
    GeneralAuthItemPopUpDialog, //授权项目
    MainContractInitProDialog //主合同立项
  },
  props: {
    // 是否作为哈图模组件
    isHTM: {
      type: Boolean,
      default: false
    },
    // 上传进度计划
    isGantt: {
      type: Boolean,
      default: false
    }
  },
  computed: {},
  methods: {
    getIsShowBtn (list) {
      //新增项目按钮的权限是否存在
      list.forEach(item => {
        if (item.object_no == "create-project-btn") {
          //新增项目按钮
          this.isShowAddProBtn = true;
        } else if (item.object_no == "delete-project") {
          this.isShowDelProBtn = true;
        } else {
          if (item.children_list) {
            this.getIsShowBtn(item.children_list);
          }
        }
      });
    },
    isShowBtn () {
      this.$nextTick(() => {
        this.isShowAddProBtn = false; //重置
        this.isShowDelProBtn = false;
        let industryUserAuth = JSON.parse(
          window.localStorage.getItem("industryUserAuth") || "[]"
        );
        // let industryUserAuth=[this.$store.state.pageAuth];//此处不用的原因是有可能从其它直接跳转过来的，此时页面的对象获取不到，所以弃用
        this.getIsShowBtn(industryUserAuth); //判断 ‘新增项目按钮’是否存在
      });
    },
    //根据主合同立项
    onMainContractInitPro () {
      this.mainConInitProDialog = true;
    },
    initCommonFunc () {
      //初始
      let isReledProject = this.isReledProjectFunc(); //判断是否有已关联的项目
      if (isReledProject == false) {
        //不存在关联的项目
        this.initFunc(); //数据初始化
      } else {
        //存在关联的项目
        this.objRowGeneral = {}; //重置
        this.geneAuthItemPopUpDialog = true;
      }
    },
    // getProRelCount (row) {//关联的项目
    //   let isRel = row.project_rela_count > 0 ? '已关联' : '未关联';//是否关联
    //   return isRel;
    // },
    //解绑项目
    onRemoveProject (row) {
      this.$confirm("是否确认解绑项目?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
        left: true
      })
        .then(() => {
          ProjectListApi.removeProject({
            data: {
              project_id: row.project_id
            }
          })
            .then(res => {
              if (res.code == 0) {
                this.$message.success("解绑成功");
                this.getProjectList(); //数据刷新
              }
            })
            .catch(error => {
              console.log(error);
            });
        })
        .catch(() => { });
    },
    onRelProDetail (row) {
      //查看关联项目
      this.objRow = Object.assign({}, row); //拷贝
      this.relProLookVisible = true;
    },
    relPro (row) {
      //关联当前项目
      ProjectListApi.proRelProId({
        data: {
          project_id: row.project_id
        }
      })
        .then(res => {
          if (res.code == 0) {
            let relaCount = res.data.rela_count; //关联的个数
            let num = relaCount; //关联的个数
            this.getProjectList(); //数据刷新
            this.$alert(
              `已和<span style="margin:0px 6px;color:red;font-weight:400;font-size:14px;">${num}个</span>项目建立关联`,
              "提示",
              {
                dangerouslyUseHTMLString: true
              }
            );
          }
        })
        .catch(error => {
          console.log(error);
        });
    },
    onRelProject (row) {
      //关联项目
      this.$confirm("是否确认关联项目?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
        left: true
      })
        .then(() => {
          this.relPro(row); //关联项目
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消操作"
          });
        });
    },
    // 下载
    downloadBIM () {
      window.open(
        "https://cloud.huizhucloud.com/rvtstatic/%E8%AE%BE%E8%AE%A1%E6%8F%92%E4%BB%B6%E5%AE%89%E8%A3%85%E5%8C%85.zip"
      );
    },
    // 删除飞轮中项目
    deleteDialogProject (row) {
      // 删除的时候判断飞轮中选择的项目是否存在待删除的项目，如有，同步删除
      let projectIdList = JSON.parse(
        window.localStorage.getItem("projectIdList") || "[]"
      );
      let choosedProjectList = JSON.parse(
        window.localStorage.getItem("choosedProjectList") || "[]"
      );
      let choosedProject = JSON.parse(
        window.localStorage.getItem("choosedProject") || "{}"
      );
      projectIdList = projectIdList.filter(item => {
        return Number(item) !== Number(row.project_id);
      });
      choosedProjectList = choosedProjectList.filter(item => {
        return Number(item.project_id) !== Number(row.project_id);
      });
      if (choosedProject.project_id === row.project_id) {
        choosedProject = {};
      }
      this.$store.dispatch("setProjectIdList", projectIdList); //选择项目的id列表
      this.$store.dispatch("setProjectList", choosedProjectList); //选择项目的完整
      this.$store.dispatch("setProject", choosedProject);
      window.localStorage.setItem("totalArrs", JSON.stringify(projectIdList));
    },
    // 删除项目
    deleteProject (row) {
      this.$confirm("项目一旦删除就不能恢复, 是否确认删除项目?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      })
        .then(() => {
          ProjectListApi.deleteProject({
            data: {
              project_id: row.project_id
            }
          }).then(res => {
            if (res.code === 0) {
              this.$message.success("删除成功");
              this.deleteDialogProject(row);
              this.getProjectList();
            }
          });
        })
        .catch(() => { });
    },
    handleCurrentChange (val) {
      this.dialogTableRow = val;
    },
    fileChange (data) {
      let dom = document.getElementById("ganttFile");
      let file = dom.files[0];
      this.upload(file, () => { });
    },
    upload (file, callback) {
      const loading = this.$loading({
        lock: true,
        text: "上传中",
        spinner: "el-icon-loading",
        background: "rgba(0, 0, 0, 0.7)"
      });
      gantt.importFromMSProject({
        data: file,
        callback: project => {
          if (project) {
            let tmp = {
              data: project.data
            };
            ProjectListApi.uploadGantt({
              data: {
                project_id: this.projectId,
                content: JSON.stringify(project)
              }
            }).then(
              res => {
                if (res.code === 0) {
                  this.$message.success("上传成功");
                }
                loading.close();
              },
              err => {
                loading.close();
              }
            );
          }

          if (callback) callback(project);
        }
      });
    },
    uploadGantt (row) {
      let dom = document.getElementById("ganttFile");
      this.projectId = row.project_id;
      dom.click();
    },
    printButton (val, row, type) {
      // console.warn(JSON.parse(window.localStorage.getItem("choosedProject")))
      // console.warn(row)
      this.queryForm = row;
      userPermissionApi
        .printTemplateList({
          data: {
            templete_url: val,
            company_id:
              Number(JSON.parse(window.localStorage.userInfo).comp_id) || "",
            project_id:
              type === "table"
                ? Number(row.project_id)
                : Number(
                  JSON.parse(window.localStorage.getItem("choosedProject"))
                    .project_id
                )
          }
        })
        .then(res => {
          if (!Array.isArray(res.data)) {
            res.data = [];
          }

          this.dialogVisiblePrintFlag = true;
          this.printTemplateList = res.data;
          // this.dialogTableRow=res.data[0]
          this.$nextTick(() => {
            this.$refs.singleTable.setCurrentRow(res.data[0]);
          });
        });
    },

    toPrintPage () {
      if (!this.dialogTableRow) return;
      if (Object.keys(this.dialogTableRow).length == 0) {
        return;
      }

      let systemName = this.dialogTableRow.categ_no;
      let suffix = ``;
      let chooseList;
      if (this.dialogTableRow.url_para) {
        chooseList = this.dialogTableRow.url_para.split(",");
      } else {
        this.$message.warning("输入参数为空");
        return;
      }

      chooseList.forEach(v => {
        if (this.queryForm[v]) {
          suffix += `${v}=${this.queryForm[v]}&`;
        }
      });
      // if(this.dialogTableRow.company_id!=='0'){
      //   suffix+=`company_id=${this.dialogTableRow.company_id}&`
      // }
      // if(this.dialogTableRow.project_id!=='0'){
      //   suffix+=`project_id=${this.dialogTableRow.project_id}&`
      // }

      suffix = suffix.substring(0, suffix.length - 1);

      let alink = document.createElement("a");
      alink.target = "_blank";
      let hrefUrl = `http://report.hibuilding.cn/ureport/preview?_u=file:${systemName}.ureport.xml&${suffix}`;

      console.warn(suffix);
      console.warn(hrefUrl);

      alink.href = hrefUrl;
      // alink.href="http://report.hibuilding.cn/ureport/preview?_u=12-16%E6%B5%8B%E8%AF%95%E6%A8%A1%E6%9D%BF&account=15622223333&pwd=hz666666&project_id=179&house_type=A&house_id=83941";
      alink.click();
      alink.remove();
    },
    search () {
      this.requestParam.page = 1;
      this.getProjectList();
    },
    // 重置表单
    reset () {
      let resetParam = JSON.parse(JSON.stringify(this.resetParam));
      this.requestParam = Object.assign(this.requestParam, resetParam);
      this.dateRange = [];
      for (var i in this.filterParams) {
        this.filterParams[i] = "";
      }
      console.log(this.filterParams);
      this.getProjectList();
    },
    // 表格排序
    sortNo () { },
    // revit弹出框中的编辑事件
    onEditDialog () {
      this.$router.push({
        path: "/editProject"
      });
    },
    // revit弹出框中的删除事件
    onDeleteDialog () {
      this.$confirm("此操作将永久删除, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      })
        .then(() => {
          this.deleteDialogVisible = false;
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消删除!"
          });
        });
    },
    // 分页
    handlePageChange (page) {
      this.requestParam.page = page;
      this.getProjectList();
    },
    // 复选框全选事件
    handleCheckAllChange (val) {
      this.checkedCities = val ? cityOptions : [];
      this.isIndeterminate = false;
    },
    // 复选框选中事件
    handleCheckedCitiesChange (value) {
      this.checkedCities = value;
      let checkedCount = value.length;
      this.checkAll = checkedCount === this.cities.length;
      this.isIndeterminate =
        checkedCount > 0 && checkedCount < this.cities.length;
    },
    // 添加项目
    createProject () {
      // 添加项目时先判断是否审核通过
      // if (this.userInfo.status !== '2') {
      //   this.$store.dispatch('toggleUserInfoDialogVisible', true)
      // } else {
      //   this.$store.dispatch('setProjectInfo', {})
      //   let editProjectInfo = {
      //     step: 1,
      //     id: 0,
      //     status: 'create'
      //   }
      //   window.localStorage.setItem('editProjectInfo', JSON.stringify(editProjectInfo))
      //   this.$router.push({
      //     path: '/editProjectStep'
      //   })
      // }
      this.$store.dispatch("setProjectInfo", {});
      let editProjectInfo = {
        step: 1,
        id: 0,
        status: "create"
      };
      window.localStorage.setItem(
        "editProjectInfo",
        JSON.stringify(editProjectInfo)
      );
      this.$router.push({
        // path: "/editProjectStep"
        path: "/operaProject", //操作项目页面
        query: { status: "create", addType: "project" }
      });
    },
    //新增工业化项目
    createIndustyProject () {
      let editProjectInfo = {
        step: 1,
        id: 0,
        status: "create"
      };
      window.localStorage.setItem(
        "editProjectInfo",
        JSON.stringify(editProjectInfo)
      );
      this.$router.push({
        path: "/operaProject", //操作项目页面
        query: { status: "create", addType: "industry" }
      });
    },
    // 跳转到构件详情页面
    goToDetail () {
      this.$router.push("/memberDetail");
    },
    // 跳转至项目详情页面
    onOpera (row, statusV) {
      this.$router.push({
        path: "/operaProject",
        query: { status: statusV, project_id: row.project_id }
      });
    },
    // 点击revit按钮
    startRevit () {
      var a = document.createElement("a");
      a.setAttribute("href", "rvt2019://");
      document.body.appendChild(a);
      a.click();
    },
    //项目列表参数
    getProject () {
      let conditions = [];
      for (var i in this.filterParams) {
        //为空不加入数组
        let obj = {};
        if (this.filterParams[i] !== "") {
          //输入框先写死
          if (i === "project_name" || i === "is_bind_jt_project") {
            obj = {
              column: i,
              symbol: i === "project_name" ? "like" : "=",
              value: this.filterParams[i]
            };
            conditions.push(obj);
          }
        }

        //日期暂时单独拿出来
        if (this.dateRange.length !== 0) {
          this.filterParams.start_time = this.dateRange[0];
          this.filterParams.end_time = this.dateRange[1];
          if (i == "start_time" || i == "end_time") {
            obj = {
              column: "created_at",
              symbol: i == "start_time" ? ">=" : "<=",
              value: this.filterParams[i]
            };
            conditions.push(obj);
          }
        }
      }
      let params = {
        conditions: conditions,
        ...this.requestParam
      };
      return params;
    },
    // 获取项目列表(1.1.8 改)
    getProjectList () {
      // console.log(this.getProject());
      this.requestParam.company_id = this.userInfo.comp_id;
      ProjectListApi.getProjectManageList({
        data: this.getProject()
      }).then(
        res => {
          if (res.code === 0) {
            this.projectList = res.data;
            this.projectList.list.map(item => {
              let map = this.majorTypeMap.get(item.major_type) || {};
              item.majorTypeName = map.name;
              item.statusName = item.status === "1" ? "未完成" : "已完成";
              item.is_bind_jt_project =
                item.is_bind_jt_project === "1" ? "是" : "否";
            });
          }
        },
        err => {
          console.log(err);
        }
      );
    },
    // 获取专业类型标准码
    getMajorTypeCode () {
      standardCodeApi
        .getStandardCodeData({
          data: {
            code_type: "major_type"
          }
        })
        .then(
          res => {
            if (res.code === 0 && res.data.list) {
              this.majorTypeList = res.data.list;
              this.convertMajorListToMap(this.majorTypeList);
              window.localStorage.setItem(
                "platformMajorTypeList",
                JSON.stringify(this.majorTypeList)
              );
            }
          },
          err => {
            console.log(err);
          }
        );
    },
    // 将专业类型列表转换为map
    convertMajorListToMap (list) {
      list.map(item => {
        this.majorTypeMap.set(item.value, item);
      });
    },
    getAuth (name) {
      // let flag = util.getAuth(name)
      return true;
    },
    // 选择业务类型
    chooseBusinessType () {
      this.requestParam.business_type = this.requestParam.business_type_list.join(
        ","
      );
    },
    // 获取业务类型标准码
    getBusinessTypeCode () {
      standardCodeApi
        .getStandardCodeData({
          data: {
            code_type: "businessType"
          }
        })
        .then(
          res => {
            if (res.code === 0 && res.data.list) {
              this.businessTypeList = res.data.list;
              window.localStorage.setItem(
                "platformBusinessTypeCode",
                JSON.stringify(this.businessTypeList)
              );
            }
          },
          err => {
            console.log(err);
          }
        );
    },
    // 作为哈图模组件时的发布功能
    publish (row) {
      this.axios
        .get("http://proxy.hibuilding.cn/hy/jump", {
          params: {
            projectCode: row.project_no,
            // projectCode: '123',
            projectName: row.project_name,
            // projectName: '北大桥项目',
            projectId: row.project_id
            // projectId: 3
          },
          headers: {
            Authorization:
              // "Bearer " + window.sessionStorage.getItem("access_token")
              "Bearer " + window.localStorage.getItem("access_token")
          }
        })
        .then(
          res => {
            if (res.data.code === 0) {
              window.open(res.data.data);
            } else {
              this.$message.error(res.data.msg);
            }
          },
          err => {
            let response = err.response.data;
            if (response.status === 500) {
              this.$message.error("服务器内部错误");
            } else if (response.status === 400) {
              this.$message.error("缺少参数");
            } else if (response.status === 404) {
              this.$message.error("地址不存在");
            } else {
              this.$message.error("服务器内部错误");
            }
          }
        );
    },

    noAuthFunc () {
      //无权限
      this.$alert(
        "该页面数据未被授权,暂时无法查看项目数据,请申请授权.",
        "提示",
        {
          dangerouslyUseHTMLString: true
        }
      );
    },
    checkCurrentProIsAuth (proId, objId) {
      ProjectListApi.checkCurrentProIsAuth({
        params: {
          project_id: proId, //项目id
          object_id: objId //权限项id
        }
      })
        .then(res => {
          if (res.data) {
            this.isLookDataAuth = res.data.check_power;
            if (this.isLookDataAuth == true) {
              //有权限
              this.initFunc(); //数据渲染
            } else {
              //无权限
              this.noAuthFunc();
            }
          }
        })
        .catch(error => {
          console.log(error);
        });
    },
    async initFunc () {
      this.userInfo = JSON.parse(
        window.localStorage.getItem("userInfo") || "{}"
      );
      let businessTypeCodeList = window.localStorage.getItem(
        "platformBusinessTypeCode"
      );
      let majorTypeList = window.localStorage.getItem("platformMajorTypeList");
      if (majorTypeList) {
        this.majorTypeList = JSON.parse(majorTypeList);
        this.convertMajorListToMap(this.majorTypeList);
      } else {
        // if (window.sessionStorage.getItem("access_token")) {
        if (window.localStorage.getItem("access_token")) {
          await this.getMajorTypeCode();
        }
      }
      if (businessTypeCodeList) {
        this.businessTypeList = JSON.parse(businessTypeCodeList);
      } else {
        await this.getBusinessTypeCode();
      }

      //判断是否有token
      // if (window.sessionStorage.getItem('access_token')) {
      this.getProjectList(); //无论如何这个都要请求；
      // }
    },
    isReledProjectFunc () {
      //判断是否有已关联的项目
      let list = this.$store.state.choosedProjectList.list || [];
      let judgeIsRelPro = false;
      if (list.length > 0) {
        list.map(item => {
          if (item.custom_project_type == 2) {
            //已关联的项目
            judgeIsRelPro = true;
          }
        });
      }
      return judgeIsRelPro;
    }
  },
  watch: {
    objRowGeneral: {
      handler (n, o) {
        if (n.project_id) {
          this.requestParam.search = n.project_name;
          this.checkCurrentProIsAuth(n.project_id, n.object_id); //检查当前项目是否有权限
        }
      },
      deep: true
    },
    relProLookVisible (n, o) {
      if (n == false) {
        this.getProjectList(); //项目列表刷新
      }
    }
  },
  activated () {
    this.initCommonFunc();
  },
  created () {
    this.isShowBtn(); //新增项目的按钮是否显示
    this.initCommonFunc(); //初始函数
  },
  async mounted () { }
};
</script>
<style scoped lang="scss">
.header-right-button {
  //background: red !important;
  display: flex;
  flex-direction: row;
  justify-content: flex-end;
  float: right;
}
@media only screen and (max-width: 767px) {
  .header-right-button {
    justify-content: flex-start;
  }
}
.el-select {
  width: 100%;
}

.status-select {
  // margin-right: 3px;
}

.projectlist-container {
  padding: 20px;

  .projectlist-top {
    background: #fff;

    // padding: 15px;
    .el-col {
      margin-bottom: 20px;
    }

    .search-btn {
      width: 70px;
      padding: 12px 10px;
    }

    .normal-select {
      width: 95%;
    }

    .location {
      padding: 0 15px;
    }

    .date-range {
      // margin-right: 15px;

      .el-date-editor {
        width: 100%;
      }
    }
  }

  .projectlist-mid {
    background: #fff;

    .checkbox-col {
      padding: 15px;
      overflow: hidden;
      border-bottom: 1px solid #ebeef5;

      .checkbox-span {
        float: left;
      }

      .checkbox-all {
        float: left;
      }

      .checkbox-item {
        float: left;
      }
    }

    .table-col {
    }
  }
}
</style>